/* This file is part of the Pardus Economy Planner.

   The Pardus Economy Planner is free software: you can redistribute it
   and/or modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.

   The Pardus Economy Planner is distributed in the hope that it
   will be useful, but WITHOUT ANY WARRANTY; without even the implied
   warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   See the GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with the Pardus Economy Planner.  If not, see
   <http://www.gnu.org/licenses/>.
*/

/* Utility scripts for Pardus Sector Tool
 * (C) Yassen 2009
 *
 * pricelist.js
 * Defines functions for getting/setting pricelist information.
 *
 * Functions:
 * void SetBuy(commodity, price, id)
 * void GetBuy(commodity, id)
 * void SetSell(commodity, price, id)
 * void GetSell(commodity, id)
 * void Import(code)
 * Pricelist Export(id)
 *
 */

Utility.Pricelist.SetBuy = function(commodity, price)
{
  Global.DisplayedPricelist.buy[commodity] = price;
}

Utility.Pricelist.GetBuy = function(commodity)
{
  return Global.DisplayedPricelist.buy[commodity];
}

Utility.Pricelist.SetSell = function(commodity, price)
{
  Global.DisplayedPricelist.sell[commodity] = price;
}

Utility.Pricelist.GetSell = function(commodity)
{
  return Global.DisplayedPricelist.sell[commodity];
}

Utility.Pricelist.GetBlank = function(name)
{
  var pricelist = new Pricelist(name, {}, {});

  for (var commodity in Global.Commodities)
  {
    if (!Global.Commodities.hasOwnProperty(commodity))
      continue;

    pricelist.buy[commodity] = 0;
    pricelist.sell[commodity] = 0;
  }

  return pricelist;
}

Utility.Pricelist.Import = function(code)
{
  var regex = new RegExp('"version":([0-9]*)', "g");
  var version = regex.exec(code)[1] * 1;
  return ImportModules[version].ImportPricelist(code);
}

Utility.Pricelist.Export = function()
{
  return ExportModule.ExportPricelist(Global.DisplayedPricelist);
}